from hanchlogger import logger
import hanchxl

class buMenChengJi(object):
    def __init__(self, is_ke_shi, ming_cheng='', qian_ren_su_qiu=None, jie_dan=0, kao_he=0, only_kao_he=0,
                 only_lian_xi=0, only_wei_lina_xi=0, only_lv_lian_xi=None, san_kao_he_zhu=0, san_lian_xi_zhu=0,
                 san_wei_lian_xi_zhu=0, san_jie_jue_zhu=0, san_wei_jie_jue_zhu=0, san_man_yi_zhu=0,
                 san_ji_ben_man_yi_zhu=0, san_bu_man_yi_zhu=0, san_lv_jie_jue_zhu=None, san_lv_lian_xi_zhu=None,
                 san_lv_man_yi_zhu=None, san_kao_he_xie=0, san_lian_xi_xie=0, san_wei_lian_xi_xie=0, san_jie_jue_xie=0,
                 san_wei_jie_jue_xie=0, san_man_yi_xie=0, san_ji_ben_man_yi_xie=0, san_bu_man_yi_xie=0,
                 san_lv_jie_jue_xie=None, san_lv_lian_xi_xie=None, san_lv_man_yi_xie=None, avg_lv_lian_xi=None,
                 avg_lv_jie_jue=None, avg_lv_man_yi=None, fen_lian_xi=None, fen_jie_jue=None, fen_man_yi=None,
                 fen_gong_dan=None, de_fen=-1, fu_ze_ren='', zhu_guan_boss='', suo_shu_area='', bao_pian_boss='',
                 fen_dang=None):
        self.isKeShi = is_ke_shi
        self.name = ''
        self.qianRenSuQiuLiang = 0
        self.jieDanZongLiang = 0
        self.kaoHeZongLiang = 0
        self.onlyKaoHeLianXi = 0
        self.onlyLvLianXi = 100
        self.onlyLianXi = 0
        self.onlyWeiLianXi = 0
        self.sanKaoHe = 0
        self.sanLvLianXi = 100
        self.sanLvJieJue = 100
        self.sanLvManYi = 100
        self.sanKaoHeShi = 0
        self.sanLianXiShi = 0
        self.sanWeiLianXiShi = 0
        self.sanJieJueShi = 0
        self.sanWeiJieJueShi = 0
        self.sanManYiShi = 0
        self.sanJiBenManYiShi = 0
        self.sanBuManYiShi = 0
        self.sanLvLianXiShi = 100
        self.sanLvJieJueShi = 100
        self.sanLvManYiShi = 100
        self.sanKaoHeQu = 0
        self.sanLianXiQu = 0
        self.sanWeiLianXiQu = 0
        self.sanJieJueQu = 0
        self.sanWeiJieJueQu = 0
        self.sanManYiQu = 0
        self.sanJiBenManYiQu = 0
        self.sanBuManYiQu = 0
        self.sanLvLianXiQu = 100
        self.sanLvJieJueQu = 100
        self.sanLvManYiQu = 100
        self.avgLvLianXi = None
        self.avgLvJieJue = None
        self.avgLvManYi = None
        self.fenLianXi = None
        self.fenJieJue = None
        self.fenManYi = None
        self.fenGongDanJiaFen = 0
        self.fenGongDanJianFen = 0
        self.deFen = -1
        self.fuZeRen = ''
        self.suoShuPianQu = ''
        self.baoPianLingDao = ''
        self.zhuGuanLingDao = ''
        self.fenDang = None

def get_kao_he_info_by_ming_xi(list_cheng_ban, sheet_source, row_start=1):
    # 处理 考核工单列表
    maxRowSource = sheet_source.max_row
    colChengBanIndex = hanchxl.get_col_index(sheet_source, '承办部门')
    colLeiXing = hanchxl.get_col_index(sheet_source, '考核情况')
    colPaiDanLeiXing = hanchxl.get_col_index(sheet_source, '承办单位类型')
    colLianXi = hanchxl.get_col_index(sheet_source, '是否联系')
    colJieJue = hanchxl.get_col_index(sheet_source, '是否解决')
    colManYi = hanchxl.get_col_index(sheet_source, '是否满意')

    logger.debug('承办部门：{}列  '.format(colChengBanIndex))
    logger.debug('考核情况：{}列'.format(colLeiXing))
    logger.debug('承办单位类型：{}列'.format(colPaiDanLeiXing))
    logger.debug('是否联系：{}列'.format(colLianXi))
    logger.debug('是否解决：{}列'.format(colJieJue))
    logger.debug('是否满意：{}列'.format(colManYi))

    numWeiChuLiKaoHe = 0
    for lineIndex in range(row_start + 1, maxRowSource + 1):
        valueChengBan = '{}'.format(sheet_source.cell(lineIndex, colChengBanIndex).value).strip().replace('(已删除)', '')
        valueLeiXing = '{}'.format(sheet_source.cell(lineIndex, colLeiXing).value).strip()
        valuePaiDanLeiXing = '{}'.format(sheet_source.cell(lineIndex, colPaiDanLeiXing).value).strip()
        valueLianxi = '{}'.format(sheet_source.cell(lineIndex, colLianXi).value).strip()
        valueJieJue = '{}'.format(sheet_source.cell(lineIndex, colJieJue).value).strip()
        valueManYi = '{}'.format(sheet_source.cell(lineIndex, colManYi).value).strip()
        logger.debug('考核 {}/{} {} {} {} {} {}'.format(lineIndex, maxRowSource, valueChengBan, valueLeiXing, valueLianxi, valueJieJue, valueManYi))
        if valueChengBan != '' and valueLeiXing != '':
            if valueLeiXing == '只考核响应率':  # 只考核响应率  工单
                if valueChengBan in list_cheng_ban:
                    list_cheng_ban[valueChengBan].kaoHeZongLiang = list_cheng_ban[valueChengBan].kaoHeZongLiang + 1
                    list_cheng_ban[valueChengBan].onlyKaoHeLianXi = list_cheng_ban[valueChengBan].onlyKaoHeLianXi + 1
                    if valueLianxi == '联系':
                        list_cheng_ban[valueChengBan].onlyLianXi = list_cheng_ban[valueChengBan].onlyLianXi + 1
                    else:
                        list_cheng_ban[valueChengBan].onlyWeiLianXi = list_cheng_ban[valueChengBan].onlyWeiLianXi + 1
                    if list_cheng_ban[valueChengBan].isKeShi == 1:
                        sheet_source.cell(lineIndex, 1).value = '已处理-科室'
                    else:
                        sheet_source.cell(lineIndex, 1).value = '已处理-社区村'
                else:
                    logger.debug('考核 {}/{} 未找到承办部门'.format(lineIndex, maxRowSource))
                    sheet_source.cell(lineIndex, 1).value = '未处理-未找到承办部门'
                    numWeiChuLiKaoHe = numWeiChuLiKaoHe + 1
            elif valueLeiXing == '考核三率':  # 考核三率 工单
                if valueChengBan in list_cheng_ban:
                    list_cheng_ban[valueChengBan].kaoHeZongLiang = list_cheng_ban[valueChengBan].kaoHeZongLiang + 1
                    list_cheng_ban[valueChengBan].sanKaoHe = list_cheng_ban[valueChengBan].sanKaoHe + 1
                    if valuePaiDanLeiXing == '直派城区':
                        list_cheng_ban[valueChengBan].sanKaoHeQu = list_cheng_ban[valueChengBan].sanKaoHeQu + 1
                        if valueLianxi == '联系' or valueLianxi == '已联系' or valueLianxi == '是':
                            list_cheng_ban[valueChengBan].sanLianXiQu = list_cheng_ban[valueChengBan].sanLianXiQu + 1
                        if valueLianxi == '未联系' or valueLianxi == '否':
                            list_cheng_ban[valueChengBan].sanWeiLianXiQu = list_cheng_ban[valueChengBan].sanWeiLianXiQu + 1
                        if valueJieJue == '解决' or valueJieJue == '已解决' or valueJieJue == '是':
                            list_cheng_ban[valueChengBan].sanJieJueQu = list_cheng_ban[valueChengBan].sanJieJueQu + 1
                        if valueJieJue == '未解决' or valueJieJue == '否':
                            list_cheng_ban[valueChengBan].sanWeiJieJueQu = list_cheng_ban[valueChengBan].sanWeiJieJueQu + 1
                        if valueManYi == '满意' or valueManYi == '非常满意':
                            list_cheng_ban[valueChengBan].sanManYiQu = list_cheng_ban[valueChengBan].sanManYiQu + 1
                        if valueManYi == '基本满意':
                            list_cheng_ban[valueChengBan].sanJiBenManYiQu = list_cheng_ban[valueChengBan].sanJiBenManYiQu + 1
                        if valueManYi == '不满意' or valueManYi == '非常不满意':
                            list_cheng_ban[valueChengBan].sanBuManYiQu = list_cheng_ban[valueChengBan].sanBuManYiQu + 1
                    elif valuePaiDanLeiXing == '343街乡镇':
                        list_cheng_ban[valueChengBan].sanKaoHeShi = list_cheng_ban[valueChengBan].sanKaoHeShi + 1
                        if valueLianxi == '联系' or valueLianxi == '已联系' or valueLianxi == '是':
                            list_cheng_ban[valueChengBan].sanLianXiShi = list_cheng_ban[valueChengBan].sanLianXiShi + 1
                        if valueLianxi == '未联系' or valueLianxi == '否':
                            list_cheng_ban[valueChengBan].sanWeiLianXiShi = list_cheng_ban[valueChengBan].sanWeiLianXiShi + 1
                        if valueJieJue == '解决' or valueJieJue == '已解决' or valueJieJue == '是':
                            list_cheng_ban[valueChengBan].sanJieJueShi = list_cheng_ban[valueChengBan].sanJieJueShi + 1
                        if valueJieJue == '未解决' or valueJieJue == '否':
                            list_cheng_ban[valueChengBan].sanWeiJieJueShi = list_cheng_ban[valueChengBan].sanWeiJieJueShi + 1
                        if valueManYi == '满意' or valueManYi == '非常满意':
                            list_cheng_ban[valueChengBan].sanManYiShi = list_cheng_ban[valueChengBan].sanManYiShi + 1
                        if valueManYi == '基本满意':
                            list_cheng_ban[valueChengBan].sanJiBenManYiShi = list_cheng_ban[valueChengBan].sanJiBenManYiShi + 1
                        if valueManYi == '不满意' or valueManYi == '非常不满意':
                            list_cheng_ban[valueChengBan].sanBuManYiShi = list_cheng_ban[valueChengBan].sanBuManYiShi + 1
                    if list_cheng_ban[valueChengBan].isKeShi == 1:
                        sheet_source.cell(lineIndex, 1).value = '已处理-科室'
                    else:
                        sheet_source.cell(lineIndex, 1).value = '已处理-社区村'
                else:
                    logger.debug('考核 {}/{} 未找到承办部门'.format(lineIndex, maxRowSource))
                    sheet_source.cell(lineIndex, 1).value = '未处理-未找到承办部门'
                    numWeiChuLiKaoHe = numWeiChuLiKaoHe + 1
    for index in list_cheng_ban:
        logger.debug('{} 接单量: {}'.format(index, list_cheng_ban[index].jieDanZongLiang))
        # 仅考核联系率 联系率
        if list_cheng_ban[index].onlyLianXi > 0:
            list_cheng_ban[index].onlyLvLianXi = round(list_cheng_ban[index].onlyLianXi * 100 / list_cheng_ban[index].onlyKaoHeLianXi, 2)
        # 市派工单成绩
        if list_cheng_ban[index].sanKaoHeShi > 0:
            list_cheng_ban[index].sanLvLianXiShi = round(list_cheng_ban[index].sanLianXiShi * 100 / list_cheng_ban[index].sanKaoHeShi, 2)
            list_cheng_ban[index].sanLvJieJueShi = round(list_cheng_ban[index].sanJieJueShi * 100 / list_cheng_ban[index].sanKaoHeShi, 2)
            numManYi = list_cheng_ban[index].sanManYiShi + list_cheng_ban[index].sanJiBenManYiShi * 0.8
            list_cheng_ban[index].sanLvManYiShi = round(numManYi * 100 / list_cheng_ban[index].sanKaoHeShi, 2)
        # 区派工单成绩
        if list_cheng_ban[index].sanKaoHeQu > 0:
            list_cheng_ban[index].sanLvLianXiQu = round(list_cheng_ban[index].sanLianXiQu * 100 / list_cheng_ban[index].sanKaoHeQu, 2)
            list_cheng_ban[index].sanLvJieJueQu = round(list_cheng_ban[index].sanJieJueQu * 100 / list_cheng_ban[index].sanKaoHeQu, 2)
            numManYi = list_cheng_ban[index].sanManYiQu + list_cheng_ban[index].sanJiBenManYiQu * 0.8
            list_cheng_ban[index].sanLvManYiQu = round(numManYi * 100 / list_cheng_ban[index].sanKaoHeQu, 2)

        # 平均联系率
        list_cheng_ban[index].avgLvLianXi = round((list_cheng_ban[index].sanLvLianXiQu + list_cheng_ban[index].sanLvLianXiShi) / 2, 2)
        list_cheng_ban[index].fenLianXi = list_cheng_ban[index].avgLvLianXi * 0.1
        # 平均解决率
        list_cheng_ban[index].avgLvJieJue = round((list_cheng_ban[index].sanLvJieJueQu + list_cheng_ban[index].sanLvJieJueShi) / 2, 2)
        list_cheng_ban[index].fenJieJue = list_cheng_ban[index].avgLvJieJue * 0.5
        # 平均满意率
        list_cheng_ban[index].avgLvManYi = round((list_cheng_ban[index].sanLvManYiQu + list_cheng_ban[index].sanLvManYiShi) / 2, 2)
        list_cheng_ban[index].fenManYi = list_cheng_ban[index].avgLvManYi * 0.4

        list_cheng_ban[index].deFen = round(list_cheng_ban[index].fenLianXi + list_cheng_ban[index].fenJieJue + list_cheng_ban[index].fenManYi, 2)

        # self.fenGongDanJiaFen = 0
        # self.fenGongDanJianFen = 0
        # self.qianRenSuQiuLiang = 0
        # self.jieDanZongLiang = 0







